//
//  personViewController.m
//  gpos_app
//
//  Created by apple on 2018/9/6.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "personViewController.h"
#import "Masonry.h"
#import "wgmeViewCell.h"
#import "GPosAPI.h"
#import "WKProgressHUD.h"
#import "SVProgressHUD.h"
#import "XMRegisterViewController.h"
#import "minerModel.h"
#import "MJRefresh.h"

@interface personViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * tableView;

@property (nonatomic,strong)NSMutableArray * modelArr;
@property (nonatomic,strong)WKProgressHUD * hud;
@end

@implementation personViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor colorWithRed:244/255.0f green:244/255.0f blue:244/255.0f alpha:1];
    self.title = @"券友人数";
    [self loadData];
    [self UILoadView];
}

- (void)loadData{

//    self.modelArr = [[NSMutableArray alloc] init];
//    __weak typeof(self) weakSelf = self;
//    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
//    NSDictionary * params = @{@"userId" : @(user)
//                              };
//    [GPosAPI requestTeamInfoWithParams:params andCallback:^(id obj) {
//        NSLog(@"obj---%@",obj);
//        if (obj==nil) {
//            
//            weakSelf.hud=[WKProgressHUD popMessage:@"请求失败" inView:self.view duration:1 animated:YES];
//        }else if ([[obj objectForKey:@"code"] intValue] == 200){
//            NSArray * arr = [[NSArray alloc] init];
//            arr = [obj objectForKey:@"data"];
//            for (NSDictionary * dic in arr) {
//                minerModel *model = [[minerModel alloc] init];
//                model.phone = [dic objectForKey:@"phone"];
//                model.nickName = [dic objectForKey:@"nickName"];
//                [weakSelf.modelArr addObject:model];
//            }
//            [weakSelf.tableView reloadData];
//            
//        }else if ([[obj objectForKey:@"code"] intValue] == 401) {
//            UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
//            //storyboard里的ID
//            XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
//            vc.navigationController.navigationBarHidden=NO;
//            //                    //设置当前窗口的根控制器
//            
//            [UIApplication sharedApplication].keyWindow.rootViewController=vc;
//            [SVProgressHUD showInfoWithStatus:@"您的账号已在其它设备登录,请重新登录!"];
//            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
//            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
//            
//        }else {
//            
//            weakSelf.hud=[WKProgressHUD popMessage:[obj objectForKey:@"message"] inView:self.view duration:1 animated:YES];
//            
//        }
//    }];
    
    
}

////上拉加载
//-(void)loadMoreShopss{
//    self.currentPage++;
//    __weak typeof(self) weakSelf = self;
//    int user = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] intValue];
//    NSDictionary * params = @{@"userId" : @(user),
//                              @"pageSize" : @(self.pageSize),
//                              @"currentPage" : @(self.currentPage)
//                              };
//    [GPosAPI requestTeamInfoWithParams:params andCallback:^(id obj) {
//        NSLog(@"obj---%@",obj);
//        if (obj==nil) {
//            [weakSelf.tableView.mj_footer endRefreshing];
//            weakSelf.hud=[WKProgressHUD popMessage:@"请求失败" inView:self.view duration:1 animated:YES];
//        }else if ([[obj objectForKey:@"code"] intValue] == 200){
//            NSArray * arr = [[NSArray alloc] init];
//            arr = [obj objectForKey:@"data"];
//            for (NSDictionary * dic in arr) {
//                minerModel *model = [[minerModel alloc] init];
//                model.phone = [dic objectForKey:@"phone"];
//                model.nickName = [dic objectForKey:@"nickName"];
//                [weakSelf.modelArr addObject:model];
//            }
//            [weakSelf.tableView reloadData];
//            [weakSelf.tableView.mj_footer endRefreshing];
//        }else if ([[obj objectForKey:@"code"] intValue] == 401) {
//            UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
//            //storyboard里的ID
//            XMRegisterViewController *vc = [mainStory instantiateInitialViewController];
//            vc.navigationController.navigationBarHidden=NO;
//            //                    //设置当前窗口的根控制器
//            
//            [UIApplication sharedApplication].keyWindow.rootViewController=vc;
//            [SVProgressHUD showInfoWithStatus:@"您的账号已在其它设备登录,请重新登录!"];
//            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
//            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
//            
//        }else {
//            
//            weakSelf.hud=[WKProgressHUD popMessage:[obj objectForKey:@"message"] inView:self.view duration:1 animated:YES];
//            
//        }
//    }];
//    
//    
//    
//}
- (void)UILoadView {
    self.tableView = [[UITableView alloc] init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    if (iPhoneX) {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).with.offset(10);
            make.left.equalTo(self.view).with.offset(0);
            make.right.equalTo(self.view).with.offset(0);
            make.bottom.equalTo(self.view).with.offset(-kBottomSafeHeight);
            
        }];
    }else{
        
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).with.offset(10);
            make.left.equalTo(self.view).with.offset(0);
            make.right.equalTo(self.view).with.offset(0);
            make.bottom.equalTo(self.view).with.offset(-10);
            
        }];
    }
    
    UIView * headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, KmainScreenWidth, 35);
    headerView.backgroundColor = [UIColor lightGrayColor];
    self.tableView.tableHeaderView = headerView;
    UIView * footerView = [[UIView alloc] init];
    self.tableView.tableFooterView = footerView;
    
    UIView * leftTopView = [[UIView alloc] init];
    leftTopView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:leftTopView];
    [leftTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView).with.offset(0);
        make.top.equalTo(headerView).with.offset(0);
        make.bottom.equalTo(headerView).with.offset(-0.5);
        make.width.equalTo(@80);
    }];
    
    UILabel * leftTopLabel = [[UILabel alloc] init];
    leftTopLabel.text = @"序号";
    leftTopLabel.textAlignment=NSTextAlignmentCenter;
    leftTopLabel.textColor = [UIColor blackColor];
    leftTopLabel.font = [UIFont systemFontOfSize:14];
    [leftTopView addSubview:leftTopLabel];
    [leftTopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftTopView).with.offset(5);
        make.right.equalTo(leftTopView).with.offset(0);
        make.centerY.equalTo(leftTopView);
    }];
    
    UIView * rightTopView = [[UIView alloc] init];
    rightTopView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:rightTopView];
    [rightTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftTopView.mas_right).with.offset(0);
        make.right.equalTo(headerView).with.offset(0);
        make.top.equalTo(headerView).with.offset(0);
        make.bottom.equalTo(headerView).with.offset(-0.5);
        
    }];
    
    UILabel * oneLabel = [[UILabel alloc] init];
    oneLabel.text = @"姓名";
    oneLabel.textAlignment=NSTextAlignmentCenter;
    oneLabel.textColor = [UIColor blackColor];
    oneLabel.font = [UIFont systemFontOfSize:14];
    [rightTopView addSubview:oneLabel];
    
    UILabel * twoLabel = [[UILabel alloc] init];
    twoLabel.text = @"电话";
    twoLabel.textAlignment=NSTextAlignmentCenter;
    twoLabel.textColor = [UIColor blackColor];
    twoLabel.font = [UIFont systemFontOfSize:14];
    [rightTopView addSubview:twoLabel];
    
    [@[oneLabel, twoLabel] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:5 leadSpacing:5 tailSpacing:5];
    
    [@[oneLabel, twoLabel] mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(rightTopView);
        
    }];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.modelArr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{//rankingCell
    
    
    wgmeViewCell * cell = [[wgmeViewCell alloc] init];
    cell = [tableView dequeueReusableCellWithIdentifier:@"wgmeCell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"wgmeViewCell" owner:self options:nil] firstObject];
    }
    
    cell.xuhaoLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
    cell.nameLabel.text = [self.modelArr[indexPath.row] nickName];
    cell.phoneLabel.text = [self.modelArr[indexPath.row] phone];
    
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 40;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed=YES;
    }
    return self;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
